package com.wkh.maker.meta;

import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.json.JSONUtil;

public class MetaManager {
    private static volatile Meta meta;
    private MetaManager(){

    }
    public static Meta getMetaobject( ) {
        if(meta == null){
            synchronized (MetaManager.class) {
                if(meta == null) {
                    meta = initMeta( );
                }
            }
        }
        return meta;
    }
    private static Meta initMeta( ) {
        String metaJson = ResourceUtil.readUtf8Str( "meta.json");
//        String metaJson = ResourceUtil.readUtf8Str( "springboot-init-meta.json");
        Meta newMeta = JSONUtil.toBean(metaJson,Meta.class);
        Meta.FileConfig fileconfig = newMeta.getFileConfig();
        // 校验和处理默认值
        MetaValidator.doValidAndFill(newMeta);
        return newMeta;
    }

}
